<template>
  <div class="main_box">
    <el-row class="header-row">
      <el-col>
        <div class="search_wrap">
          <el-form :inline="true" :model="filters" class="demo-form-inline" ref="searchForm">
            <el-form-item prop="modelName">
              <el-input v-model="filters.modelName" placeholder="项目组名称" clearable></el-input>
            </el-form-item>
            <el-form-item prop="modelCode">
              <el-input v-model="filters.modelCode" placeholder="项目组编号" clearable></el-input>
            </el-form-item>
            <el-form-item>
              <el-button icon="el-icon-search" type="primary" id="searchButton" @click="onSearch">查询</el-button>
              <el-button icon="el-icon-refresh-left" @click="resetForm">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
      <el-col>
        <div class="opration_wrap">
          <div>
            <el-tooltip content="刷新" placement="top">
              <el-button circle icon="el-icon-refresh-right" @click="reload" size="mini"></el-button>
            </el-tooltip>
            <el-tooltip content="返回" placement="top">
              <el-button circle icon="fa fa-mail-forward" @click="returnList" size="mini"></el-button>
            </el-tooltip>
          </div>

          <div>
            <el-button type="primary" v-has="permissionAdd" plain icon="fa fa-plus" @click="handleClickAdd()" size="mini"> 新增</el-button>
          </div>
        </div>
      </el-col>
    </el-row>

    <el-row ref="tableRow">
      <h1>模板名称：{{ PriceModelName }}</h1>
      <!-- 列表 -->
      <el-table :data="dataList" :fit="true" highlight-current-row>
        <el-table-column label="序号" type="index" width="50" align="center"> </el-table-column>
        <el-table-column prop="itemId" label="项目组ID" align="center"></el-table-column>
        <el-table-column prop="itemName" label="项目组名称" align="center"></el-table-column>
        <el-table-column prop="itemCode" label="项目组编号" align="center"></el-table-column>
        <el-table-column prop="itemPrice" label="原价" align="center"></el-table-column>
        <el-table-column prop="itemSalePrice" label="合作价" align="center"></el-table-column>
        <el-table-column prop="createDate" label="创建时间" align="center"></el-table-column>
        <el-table-column label="操作" width="200" fixed="right">
          <template slot-scope="scope">
            <el-button v-has="permissionCheck" @click="handleClickEditor(scope.row)" size="mini">编 辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页工具条 -->
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.pageNo"
        :page-sizes="[20, 50, 100]"
        :page-size="page.pageSize"
        layout="total, sizes, jumper, next, pager, prev"
        :total="page.pageTotal"
      ></el-pagination>
    </el-row>
  </div>
</template>
<script>
import * as message from '@/constants/message';
import PriceModelApi from '@/api/pricemodel/pricemodel';
export default {
  name: 'PriceModelItemManagement',
  inject: ['reload'], //注入局部刷新
  data() {
    return {
      PriceModelName: '',
      PriceModelId: '',
      filters: {
        itemPriceModelId: '',
        modelName: '',
        modelCode: '',
        modelType: '',
      },

      dataList: [],
      stateList: [
        { label: '医院', value: 1 },
        { label: '医检', value: 2 },
        // { label: "删除", value: -1, disabled: true }
      ],
      page: {
        pageNo: 1,
        pageTotal: 0,
        pageSize: 20,
      },
      uploadAccept: 'all', // 上传的文件类型 0.all 1.pdf 2.img 3.video 4.excel
      uploadData: {
        fileDesc: '',
        uploadFile: '',
      },

      permissionAdd: 'SYSTEM_MANAGER_ITEM_PRICEMODEL_LIST_ADD',
      permissionImport: 'SYSTEM_MANAGER_ITEM_PRICEMODEL_LIST_IMPORT',
      permissionCheck: 'SYSTEM_MANAGER_ITEM_PRICEMODEL_LIST_SEE',
      permissionEdit: 'SYSTEM_MANAGER_ITEM_PRICEMODEL_LIST_EDIT',
      permissionUpStatus: 'SYSTEM_MANAGER_ITEM_PRICEMODEL_LIST_DELETE',
      permissionState: 'SYSTEM_MANAGER_ITEM_PRICEMODEL_LIST_STATE',
    };
  },
  created() {
    document.onkeydown = function (e) {
      let key = window.event.keyCode;
      if (key == 13) {
        document.getElementById('searchButton').click();
      }
    };
  },
  mounted() {
    this.init();
  },
  activated() {
    // if (this.$route.meta.keepAlive) {
    this.init();
    // }
  },
  methods: {
    init() {
      let _this = this;
      if (_this.$route.query.id) {
        _this.PriceModelId = _this.$route.query.id;
        _this.PriceModelName = _this.$route.query.name;
      }
      _this.listData();
      _this.getTableHeight();
    },

    onSearch() {
      this.page.pageNo = 1;
      this.listData();
    },
    resetForm() {
      this.$refs.searchForm.resetFields();
      this.onSearch();
    },
    formatPrice(row, column, cellValue) {
      if (!cellValue) {
        return '未知';
      } else {
        return cellValue + ' 元';
      }
    },
    formatState(row, column, cellValue) {
      if (cellValue === -1) {
        return '已删除';
      } else if (cellValue === 0) {
        return '已禁用';
      } else if (cellValue === 1) {
        return '启用中';
      }
    },
    handleSizeChange(size) {
      let _this = this;
      _this.page.pageSize = size;
      _this.listData();
    },
    handleCurrentChange(val) {
      let _this = this;
      _this.page.pageNo = val;
      _this.listData();
    },
    handleClickEditor(row) {
      // 编辑
      let _this = this;
      _this.$router.push({
        path: '/item/PriceModelSubAdd',
        query: { itemPriceId: row.itemPriceId },
      });
    },
    handleClickAdd() {
      // 新增
      let _this = this;
      _this.$router.push({
        path: '/item/PriceModelSubAdd',
        query: { itemPriceModelId: this.PriceModelId, itemPriceModelName: this.PriceModelName },
      });
    },
    listData() {
      // 获取数据
      let _this = this;
      let cond = {
        itemPriceModelId: _this.PriceModelId,
        pageNo: _this.page.pageNo,
        pageSize: _this.page.pageSize,
        itemName: _this.filters.modelName,
        itemCode: _this.filters.modelCode,
      };
      PriceModelApi.priceModelListc(cond).then((res) => {
        _this.dataList = res.data.list;
        if (res.data.list.modelType) {
          this.dataList.modelType = String(res.data.list.modelType);
        }
        _this.page.pageTotal = res.data.total;
      });
    },
    returnList() {
      this.$router.push({ path: '/items/priceModelItemManagement' });
    },
  },
};
</script>
<style lang="scss" src="@/assets/css/views/content.scss" scope></style>
